/**
 * Created by Administrator on 2017/11/16 0016.
 */
/**
 * Created by Administrator on 2017/11/16 0016.
 */
var common = require('../../common');
var pool = require('../index');
var mysql = require('mysql');
var YjxBaseModel = require('./YjxBaseModel');
var CONFIG = require('../../config');


var YjxUserModel = function (obj) {
    YjxBaseModel.call(this,obj);
};

YjxUserModel.prototype = new YjxBaseModel();

// 取得表名
YjxUserModel.prototype.getTableName = function(){
    return 'yjx_user';
};
// 取得查询语句中where 后面匹配主键的条件（需要各派生类进行重载）
YjxUserModel.prototype.getWhereConditionOfKeyEqual = function(){
    return 'user_id='+this.user_id;
};





/**
 * 获取用户详细信息
 * @author 李强
 * @date   2017-11-17
 * @param userId 用户唯一标识
 * @param callback 回调
 *                err:错误信息
 *                data:返回数据
 * */

YjxUserModel.prototype.getThirdPartyUserInfo = function(userId,callback){
    pool.pool.getConnection(function(getConnectErr,connection) {
        if (getConnectErr) {
            console.log('YjxUserModel.getThirdPartyUserInfo getConnectErr: ' + getConnectErr);
            return callback(getConnectErr, null);
        }
        //查询userId对应的所有第三方信息
        var sql= "SELECT t.* " +
            " FROM yjx.yjx_third_party_user t " +
            " WHERE user_id = " + userId +
            " AND del_flg = 0";
        console.log(sql);
        connection.query(sql, function (error, results) {
            connection.release();
            if (error) {
                console.log('YjxUserModel.getThirdPartyUserInfo Err: ' + error);
                return callback(error, null);
            }
            return callback(null, results)
        })
    })
};

//------------------------------------------------------------------------------
/**
 * 根据账号密码获取用户信息
 * @author xc
 * @date   2018-07-09
 *
 * @param param.account 账号
 * @param param.password 密码
 * @param param.orgTypes 组织类型 (数组:[100,300,400])
 * @param callback 回调
 */
YjxUserModel.prototype.getUserInfoByAcAndPw = function(param,callback){
    var THIS=this;
    pool.pool.getConnection(function(getConnectErr,connection) {
        if (getConnectErr) {
            console.log('YjxUserModel.getUserInfoByAcAndPw getConnectErr: ' + getConnectErr);
            return callback(getConnectErr, null);
        }

        var sql= " SELECT t.* "+
            " ,r.org_id, o.type AS org_type, o.name AS org_name, r.role, b.field1 AS mobile " +
            " FROM yjx.yjx_user t " +
            " INNER JOIN yjx.yjx_org_r r ON r.user_id = t.user_id AND r.state=10 AND r.del_flg = 0 "+
            " INNER JOIN yjx.yjx_org o ON o.org_id = r.org_id AND o.del_flg = 0 ";
        if(param.orgTypes && param.orgTypes.length>0) {
            sql += " AND o.type IN ("+(param.orgTypes||[]).join(',')+")";
        }
        sql += " LEFT JOIN yjx.yjx_third_party_user b ON b.user_id=t.user_id AND b.account_type=10 AND b.del_flg=0 ";
        sql += " WHERE t.del_flg=0 "+
            " AND t.account= ? "+ // param.account+
            " AND t.password= ? "+ // param.password+
            " ORDER BY t.user_id DESC, o.org_id DESC, r.create_time DESC ";

        var sqlValue = [param.account, param.password];
        var sql = mysql.format(sql, sqlValue);

        console.log(sql);
        connection.query(sql, function (error, results) {
            connection.release();
            if (error) {
                console.log('YjxUserModel.getUserInfoByAcAndPw Err: ' + error);
                return callback(error, null);
            }
            return callback(null, results)
        })
    })
};

//------------------------------------------------------------------------------
/**
 * 获取用户详细信息(带第三方信息)
 * @author xc
 * @date   2017-11-20
 * @param userId 用户唯一标识
 * @param callback 回调
 *                err:错误信息
 *                data:返回数据
 */

YjxUserModel.prototype.getUserInfoWithThirdPartyInfo = function(userId,callback){
    var THIS=this;
    pool.pool.getConnection(function(getConnectErr,connection) {
        if (getConnectErr) {
            console.log('YjxUserModel.getUserInfoWithThirdPartyInfo getConnectErr: ' + getConnectErr);
            return callback(getConnectErr, null);
        }

        var sql= " SELECT u.*, t.tpu_id, t.account_type, t.nickname AS tpu_nickname, "+
            " t.profile_photo AS tpu_profile_photo, t.field1, t.field2, t.field3 " +
            " FROM yjx.yjx_user u " +
            " LEFT JOIN yjx.yjx_third_party_user t ON t.del_flg = 0 AND t.user_id=u.user_id "+
            " WHERE u.del_flg=0 AND u.user_id = " + userId +
            " ORDER BY t.account_type, t.tpu_id ";

        console.log(sql);
        connection.query(sql, function (error, results) {
            connection.release();
            if (error) {
                console.log('YjxUserModel.getUserInfoWithThirdPartyInfo Err: ' + error);
                return callback(error, null);
            }
            return callback(null, results)
        })
    })
};

//***************************************************************************************************************
/**
 * 获取组织用户列表sql
 *
 * @param bForCnt  是否只求列表Cnt
 * @param {Object} param 筛选参数
 * @param {Number} param.pageNum    页码
 * @param {Number} param.pageSize   页容量
 * @param {Array}  param.orgId      组织id
 * @param {Number} [param.orgType]  组织类型(可选)
 * @param {Number} [param.mobile]   用户手机号(可选)
 * @param {Number} [param.role]     用户角色(可选)
 * @param {String} [param.nickname] 用户昵称(可选)
 * @param {Number} [param.userId]   用户id(可选)
 * @returns {string}
 */
function sql_getOrgUserInfoList(bForCnt,param) {

    var sql = '';
    if(bForCnt) {
        sql += " SELECT COUNT(u.user_id) AS `count` ";
    } else  {
        sql += " SELECT u.user_id, u.account, u.user_type, u.gender, u.real_name, u.nickname "+
            " ,u.birth_year, u.birth_month, u.birth_day, u.user_desc, u.addr_id, u.qr_code "+
            " ,u.profile_photo, u.signature, u.evaluation, u.note "+
            " ,o.org_id, o.type AS org_type, r.role, r.desc AS org_r_desc "+
            " ,DATE_FORMAT(u.create_time,'%Y/%m/%d %H:%i:%s') AS fmt_create_time "+
            " ,DATE_FORMAT(u.update_time,'%Y/%m/%d %H:%i:%s') AS fmt_update_time "+
            " ,b.field1 AS mobile ";
    }
    sql += " FROM " +
        " yjx.yjx_user u" +
        " INNER JOIN yjx.yjx_org_r r ON r.user_id=u.user_id AND r.del_flg=0 AND r.state=10 ";
    if(param.role && param.role>0) {
        sql += " AND r.role & "+param.role+" >0 ";
    }
    sql += " INNER JOIN yjx.yjx_org o ON o.org_id=r.org_id ";
    if(param.orgId && param.orgId>0) {
        sql += " AND o.org_id= "+param.orgId;
    }
    if(param.orgType && param.orgType>0) {
        sql += " AND o.type= "+param.orgType;
    }

    sql += " LEFT JOIN yjx.yjx_third_party_user b ON b.user_id = u.user_id AND b.del_flg=0 AND b.account_type=10 ";
    sql += " WHERE u.del_flg = 0 ";
    if(param.userId && param.userId>0) {
        sql += " AND u.user_id= "+param.userId;
    }
    if(param.nickname && (param.nickname+'').length>0) {
        sql += " AND u.nickname like CONCAT('%','" +param.nickname+ "','%') ";
    }
    if(param.mobile && (param.mobile+'').length>0) {
        sql += " AND b.field1 like CONCAT('%','" +param.mobile+ "','%') ";
    }

    sql += " ORDER BY u.update_time DESC " ;
    if (!bForCnt) {
        if (typeof param.pageNum !== 'undefined' && param.pageNum !== null &&
            typeof param.pageSize !== 'undefined' && param.pageSize !== null)
        {
            var skipCnt = Number(param.pageNum||'0') * Number(param.pageSize||'0');
            sql += " LIMIT " + skipCnt + "," + Number(param.pageSize||'0');
        }
    }

    return sql;
}
// 获取组织用户列表Cnt
YjxUserModel.prototype.getOrgUserInfoListCnt = function (param,callback){
    pool.pool.getConnection(function (getConErr, connection) {
        if (getConErr) {
            console.log('YjxUserModel.js [getOrgUserInfoListCnt] getConErr' + getConErr);
            return callback(getConErr, null);
        }
        var sql = sql_getOrgUserInfoList(true,param);
        console.log(sql);
        connection.query(sql, function (queryErr, results) {
            connection.release();
            if (queryErr) {
                console.log('YjxUserModel.js [getOrgUserInfoListCnt] queryErr' + queryErr)
            }
            return callback(queryErr, results[0].count);
        });
    })
};
// 获取组织用户列表信息
YjxUserModel.prototype.getOrgUserInfoList = function (param,callback){
    pool.pool.getConnection(function (getConErr, connection) {
        if (getConErr) {
            console.log('YjxUserModel.js [getOrgUserInfoList] getConErr' + getConErr);
            return callback(getConErr, null);
        }
        var sql = sql_getOrgUserInfoList(false,param);
        console.log(sql);
        connection.query(sql, function (queryErr, results) {
            connection.release();
            if (queryErr) {
                console.log('YjxUserModel.js [getOrgUserInfoList] queryErr' + queryErr)
            }
            return callback(queryErr, results);
        });
    })
};
//***************************************************************************************************************

/**
 * 获取用户详细信息
 * @author 毛凯
 * @date   2018-6-11
 * @param userName  用户名
 * @param password  用户秘密
 * @param userId 用户id
 * @param callback 回调
 *                err:错误信息
 *                data:返回数据
 */

YjxUserModel.prototype.getUserInfoWithUserOrg= function(userName,password,userId,callback){
    var THIS=this;
    pool.pool.getConnection(function(getConnectErr,connection) {
        if (getConnectErr) {
            console.log('YjxUserModel.getUserInfoWithThirdPartyInfo getConnectErr: ' + getConnectErr);
            return callback(getConnectErr, null);
        }

        var sql= "	SELECT	" +
                "	  yu.user_id AS id,	" +
                "	  yu.nickname AS nickName,	" +
                "	  yor.role,	" +
                "	  yo.org_id AS orgId,	" +
                "	  yo.name AS orgName	" +
                "	FROM	" +
                "	  yjx.yjx_user yu,	" +
                "	  yjx.yjx_org_r yor,	" +
                "	  yjx.yjx_org yo	" +
                "	WHERE yor.user_id = yu.user_id " ;
            if(userName && password && userName.length >0 && password.length > 0){
             sql +="  AND yu.account = '"+userName+"'	" ;
             sql +="  AND yu.password = '"+password+"'	" ;
            }
            if (userId && userId >0){
               sql += "  AND yu.user_id = "+userId+" ";
            }
            sql += "  AND yor.org_id = yo.org_id  " +
                "	  AND yo.type = 300	" +
                "	  AND yu.del_flg = 0	" +
                "	  AND yor.del_flg = 0	" +
                "	  AND yo.del_flg = 0	" ;
            console.log(sql);
        connection.query(sql, function (error, results) {
            connection.release();
            if (error) {
                console.log('YjxUserModel.getUserInfoWithThirdPartyInfo Err: ' + error);
                return callback(error, null);
            }
            return callback(null, results)
        })
    })
};

/**
 * 查询微信第三方平台关联用户信息
 *
 * @author 王俊
 * @date 2017-07-19
 *
 * @param {Object} option                   查询选项
 * @param {Number} [option.account_type]    账号类型
 * @param {String} option.field1            微信 unionId
 * @param {String} [option.field2]          微信 openId
 * @param {Function} callback               回调函数
 *                      error: 错误
 *                      thirdParts: 三方用户资料数组(三方表行数据)
 */
YjxUserModel.prototype.selectWXAssociatedThirdPartUsers = function (option, callback) {
    pool.pool.getConnection(function (getConErr, connection) {
        if (getConErr) {
            console.log('YjxUserModel.js [selectWXAssociatedThirdPartUsers] getConErr' + getConErr);
            return callback(getConErr, null);
        }
        var sql =
            ' SELECT ytpu.* ' +
            ' FROM yjx.yjx_third_party_user ytpu, ' +
            '      yjx.yjx_user yu ' +
            ' WHERE ytpu.del_flg=0 ' +
            '   AND (ytpu.account_type =20 ' +  // 微信
            '        OR ytpu.account_type =50 ' + // 网站
            '        OR ytpu.account_type BETWEEN 200 AND 300) ' + // 微信小程序
            '   AND ytpu.field1 = "'+option.field1+'" ' +
            '   AND yu.del_flg=0 ' +
            '   AND yu.user_id = ytpu.user_id ' +
            '   AND yu.user_type = 20 ';    // 普通用户
        console.log(sql);
        connection.query(sql, function (queryErr, results) {
            connection.release();
            if (queryErr) {
                console.log('YjxUserModel.js [selectWXAssociatedThirdPartUsers] queryErr' + queryErr)
            }
            return callback(queryErr, results);
        });
    })
};


/**
 * 获取网红公司 个人用户信息
 * @author 李琦
 * @param callback
 */
YjxUserModel.prototype.getRedWedUserInfo= function(param,callback){
    var THIS=this;
    pool.pool.getConnection(function(getConnectErr,connection) {
        if (getConnectErr) {
            console.log('YjxUserModel.getRedWedUserInfo error' + getConnectErr);
            return callback(getConnectErr, null);
        }
        var sql = "SELECT u.user_id, ogr.`desc`, t.field1, u.gender"+
            "	, CONCAT_WS('-', u.birth_year, u.birth_month, u.birth_day) AS birth"+
            "	, x1.address "+
            " FROM (yjx.yjx_user AS u,yjx.yjx_org_r AS ogr) "+
            "	LEFT JOIN yjx.yjx_third_party_user t "+
            "	ON ( t.user_id = u.user_id "+
            "		AND t.del_flg = 0"+
            "		AND t.account_type = 10) "+
            "	LEFT JOIN ( "+
            "		SELECT xx.* "+
            "		FROM ("+
            "			SELECT ya.addr_id, ya.user_id"+
            "				, CONCAT_WS('-', r.`name`, r2.`name`, r3.`name`) AS address "+
            "			FROM yjx.yjx_address ya "+
            "				LEFT JOIN itbour.itb_area r "+
            "				ON ya.prov = r.id "+
            "					AND r.del_flg = 0 "+
            "				LEFT JOIN itbour.itb_area r2 "+
            "				ON ya.city = r2.id "+
            "					AND r2.del_flg = 0 "+
            "				LEFT JOIN itbour.itb_area r3 "+
            "				ON ya.dist = r3.id "+
            "					AND r3.del_Flg = 0 "+
            "			WHERE ya.del_flg = 0 "+
            "				AND ya.type = 1 "+
            "			ORDER BY ya.update_time DESC "+
            "		) xx "+
            "		GROUP BY xx.user_id "+
            "	) x1 "+
            "	ON x1.user_id = u.user_id AND x1.addr_id = u.addr_id "+
            "WHERE u.del_flg = 0 AND ogr.user_id = u.user_id " +
            "AND ogr.del_flg = 0 "; // AND ogr.org_id=30  AND u.user_id = 3
        if (param.orgId && Number(param.orgId)>0 && param.userId && Number(param.userId)>0){
            sql+=  "AND ogr.org_id='"+param.orgId+"' AND u.user_id = '"+param.userId+"'";
        }
        console.log(sql);
        connection.query(sql, function (error, results) {
            connection.release();
            if (error) {
                console.log('YjxUserModel.getRedWedUserInfo error' + error);
                return callback(error, null);
            }
            return callback(null, results)
        })
    })
};

/**
 * 获取网红公司 平台信息
 * @author 李琦
 * @param callback
 */
YjxUserModel.prototype.getRedWedUserPlat = function(param,callback){
    pool.pool.getConnection(function(getConnectErr,connection) {
        if (getConnectErr) {
            console.log('YjxUserModel.getRedWedUserPlat error' + getConnectErr);
            return callback(getConnectErr, null);
        }
        var sql = "SELECT  efc.user_id,efc.field1 infoId,efc.field2 platId,cd.`value`," +
            "efc.field3 fansNum,efc.field4 likeNum " +
            "FROM yjx.yjx_user_ext_info_cust efc, " +
            "yjx.yjx_cd_info cd " +
            "where efc.del_flg=0 " +
            "AND efc.type=10 " +
            "AND cd.info_id = efc.field1 " +
            "AND cd.type=104 ";
        if (param.userId && Number(param.userId)>0){
            sql+=  "AND efc.user_id = '"+param.userId+"'";
        }
        if (param.plat && Number(param.plat)>0){
            sql+=  "AND efc.field1 = '"+param.plat+"'";
        }
        console.log(sql);
        connection.query(sql, function (error, results) {
            connection.release();
            if (error) {
                console.log('YjxUserModel.getRedWedUserPlat error' + error);
                return callback(error, null);
            }
            return callback(null, results)
        })
    })
};

/**
 * 获取网红公司 用户标签
 * @author 李琦
 * @param callback
 */
YjxUserModel.prototype.getRedWedUserLabe = function(param,callback){
    pool.pool.getConnection(function(getConnectErr,connection) {
        if (getConnectErr) {
            console.log('YjxUserModel.getRedWedUserLabe error' + getConnectErr);
            return callback(getConnectErr, null);
        }
        var sql = "SELECT ef.user_id, cd.info_id,cd.`value`, cd.type " +
            "FROM yjx.yjx_user_ext_info_r ef, yjx.yjx_cd_info cd " +
            "WHERE (ef.del_flg = 0 " +
            "AND cd.info_id = ef.info_id " +
            "AND cd.type = 103 " +
            "AND cd.del_flg = 0) ";
        if (param.userId && Number(param.userId)>0) {
            sql+=  "AND ef.user_id = '"+param.userId+"'";
        }
        console.log(sql);
        connection.query(sql, function (error, results) {
            connection.release();
            if (error) {
                console.log('YjxUserModel.getRedWedUserLabe error' + error);
                return callback(error, null);
            }
            return callback(null, results)
        })
    })
};

/**
 * 获取所有标签
 * @author 李琦
 * @param callback
 */
YjxUserModel.prototype.getRedWedAllLabe = function(param,callback){
    pool.pool.getConnection(function(getConnectErr,connection) {
        if (getConnectErr) {
            console.log('YjxUserModel.getRedWedAllLabe error' + getConnectErr);
            return callback(getConnectErr, null);
        }
        var sql = "SELECT yc.info_id value ,yc.`value` label FROM " +
            "yjx.yjx_cd_info yc " +
            "where yc.type=103 " +
            "AND yc.state=3";

        console.log(sql);
        connection.query(sql, function (error, results) {
            connection.release();
            if (error) {
                console.log('YjxUserModel.getRedWedAllLabe error' + error);
                return callback(error, null);
            }
            return callback(null, results)
        })
    })
};


/**
 * 给网红用户添加平台资料
 * @author 李琦
 * @param callback
 */
YjxUserModel.prototype.addUserPlat = function(param,callback){
    pool.pool.getConnection(function(getConnectErr,connection) {
        if (getConnectErr) {
            console.log('YjxUserModel.addUserPlat error' + getConnectErr);
            return callback(getConnectErr, null);
        }
        var sql = "INSERT INTO yjx.yjx_user_ext_info_cust (user_id, type, field1, field2, field3," +
            "field4, create_time, update_time, update_by)" +
            "VALUES ('"+param.userId+"', 10,'"+param.plat+"','"+param.platId+"'," +
            " '"+param.fansNum+"','"+param.likeNum+"', SYSDATE(), SYSDATE(), '"+param.currentUserId+"')";

        console.log(sql);
        connection.query(sql, function (error, results) {
            connection.release();
            if (error) {
                console.log('YjxUserModel.addUserPlat error' + error);
                return callback(error, null);
            }
            return callback(null, null)
        })
    })
};


/**
 * 修改网红平台资料
 * @author 李琦
 */
YjxUserModel.prototype.editUserPlat = function(param,callback){
    pool.pool.getConnection(function(getConnectErr,connection) {
        if (getConnectErr) {
            console.log('YjxUserModel.delUserPlat error' + getConnectErr);
            return callback(getConnectErr, null);
        }
        var sql = "UPDATE " +
            "yjx.yjx_user_ext_info_cust efc " +
            "SET " +
            "efc.del_flg=?,efc.update_by=? " +
            "WHERE efc.user_id=? " +
            "AND efc.field1=?";
        var sqlValue = [param.del_flg, param.currentUserId,param.userId,param.info_id];
        var sql = mysql.format(sql, sqlValue);

        console.log(sql);
        connection.query(sql, function (error, results) {
            connection.release();
            if (error) {
                console.log('YjxUserModel.delUserPlat error' + error);
                return callback(error, null);
            }
            return callback(null, null)
        })
    })
};


/**
 * 微信自动登录/注册(app/web/mp)
 *
 * @author 王俊
 * @date 2018-08-8
 *
 * @param {Object} options
 * @param {Object} options.unionId
 * @param {Object} options.openId
 * @param {Object} options.accountType
 * @param {Object} options.nickName
 * @param {Object} options.avatarUrl
 * @param {Function} callback 回调函数
 *                      error
 *                      userId
 */

YjxUserModel.prototype.wxLoginAndAutoReg = function(options, callback) {
    pool.pool.getConnection(function(getConnectErr,connection) {
        if (getConnectErr) {
            console.log('YjxUserModel.wxLoginAndAutoReg error' + getConnectErr);
            return callback(getConnectErr, null);
        }
        var sql ='CALL `proc_yjx_wxLoginAndAutoReg`( "'+options.unionId+'", "'+options.openId+'", '+options.accountType+', "'+options.nickName+'", "'+options.avatarUrl+'", @retCd)';
        console.log(sql);
        connection.query(sql, function (error, results) {
            connection.release();
            if (error) {
                console.log('YjxUserModel.wxLoginAndAutoReg error' + error);
                return callback(error, null);
            }
            // 没有userId 认为失败
            if(!results || results.length<=0
                || !results[0] || results[0].length<=0 ||
                !results[0][0].user_id)
            {
                return callback('登录失败', null);
            }
            return callback(error, results[0][0].user_id)
        })
    })
};

/**
 * 更新网红用户基本信息
 * @author 李琦
 */
YjxUserModel.prototype.editWebRedUserBaseInfo = function(param,callback){
    pool.pool.getConnection(function(getConnectErr,connection) {
        if (getConnectErr) {
            console.log('YjxUserModel.editWebRedUserBaseInfo error' + getConnectErr);
            return callback(getConnectErr, null);
        }
        var sql = "UPDATE " +
            "yjx.yjx_user u " +
            "SET u.gender = ?, " +
            "u.birth_year= ?,u.birth_month=?, " +
            "u.birth_day=?,u.update_by=?, " +
            "u.update_time=SYSDATE() " +
            "WHERE u.del_flg=0 " +
            "AND u.user_id=?";
        var sqlValue = [param.gender,param.birth_year,param.birth_month,param.birth_day,
            param.currentUserId,param.userId];
        var sql = mysql.format(sql, sqlValue);

        console.log(sql);
        connection.query(sql, function (error, results) {
            connection.release();
            if (error) {
                console.log('YjxUserModel.editWebRedUserBaseInfo error' + error);
                return callback(error, null);
            }
            return callback(null, null)
        })
    })
};

/**
 * 删除 用户之前标签
 * @author 李琦
 */
YjxUserModel.prototype.delWebRedUserOldLab = function(param,callback){
    pool.pool.getConnection(function(getConnectErr,connection) {
        if (getConnectErr) {
            console.log('YjxUserModel.delWebRedUserOldLab error' + getConnectErr);
            return callback(getConnectErr, null);
        }
        var sql = "UPDATE yjx.yjx_user_ext_info_r u " +
            "SET u.del_flg=1, " +
            "u.update_by =?, " +
            "u.update_time=SYSDATE() " +
            "WHERE u.user_id=? " +
            "AND u.type=103 " +
            "AND u.del_flg=0 and u.state=30";
        var sqlValue = [param.currentUserId,param.userId];
        var sql = mysql.format(sql, sqlValue);

        console.log(sql);
        connection.query(sql, function (error, results) {
            connection.release();
            if (error) {
                console.log('YjxUserModel.delWebRedUserOldLab error' + error);
                return callback(error, null);
            }
            return callback(null, null)
        })
    })
};

/**
 * 插入新的标签
 * @author 李琦
 */
YjxUserModel.prototype.insertUserLab = function(infoId,param,callback){
    pool.pool.getConnection(function(getConnectErr,connection) {
        if (getConnectErr) {
            console.log('YjxUserModel.insertUserLab error' + getConnectErr);
            return callback(getConnectErr, null);
        }
        var sql = "INSERT INTO yjx.yjx_user_ext_info_r (user_id, info_id, type, state, create_time" +
            ", update_time, update_by)" +
            "VALUES (?, ?, 103, 30, SYSDATE(),SYSDATE(),?)";
        var sqlValue = [param.userId,infoId,param.currentUserId];
        var sql = mysql.format(sql, sqlValue);

        console.log(sql);
        connection.query(sql, function (error, results) {
            connection.release();
            if (error) {
                console.log('YjxUserModel.insertUserLab error' + error);
                return callback(error, null);
            }
            return callback(null, null)
        })
    })
};





















module.exports = YjxUserModel;